package com.sdk.bigdata.model;


import com.alibaba.fastjson.annotation.JSONField;
import com.sdk.bigdata.exceptions.DataException;

import java.util.HashMap;
import java.util.Map;

// 用户信息
public class User extends BaseModel {

    private String uid;

    @JSONField(name = "uid_type")
    private String uidType;

    public User( String type, String uid, String uidType,Map<String, Object> properties) {
        super(type, properties);
        this.uid = uid;
        this.uidType = uidType;
    }

    public User() {
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getUidType() {
        return uidType;
    }

    public void setUidType(String uidType) {
        this.uidType = uidType;
    }

    @Override
    public void validAttribute() {
        if (null == this.getType() || (!this.getType().equals("profile_set") && !this.getType().equals("profile_delete")
                && this.getType().equals("profile_create"))) {
            throw new DataException("property [Type] is not profile_set or profile_delete or profile_create");
        }
        this.setTime(System.currentTimeMillis());
        //check uid
        if (null == this.getUid() || this.getUid().equals("")) {
            throw new DataException("property [uid] can't be empty");
        }
        if (this.getUid().length() > 255) {
            throw new DataException("the max length of property [uid] is 255");
        }

        if (null == this.getProperties()) {
            this.setProperties(new HashMap<>());
        }
    }
}
